<template>
  <div class="login-page">

    <div class="logo">
      <img src="~@/assets/images/logo.png" alt="">
    </div>

     <div class="logo-words">
        <span >支持健康产业决策与连接的领导者</span>
     </div>

     <div class="line-spit">


     </div>

    <div class="login login-container">
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
        <div class="title-container">
          <h3 class="title">中康云-数据中台</h3>
        </div>
        <el-form-item prop="username" class="login-input">
          <span class="svg-container">
            <svg-icon icon-class="user" />
          </span>
          <el-input
            ref="username"
            v-model.trim="loginForm.username"
            placeholder="请输入账号"
            name="username"
            type="text"
            tabindex="1"
            autocomplete="on"
          />
        </el-form-item>

        <el-form-item prop="password">
          <span class="svg-container">
            <svg-icon icon-class="password"/>
          </span>
          <el-input
            :key="passwordType"
            ref="password"
            v-model="loginForm.password"
            :type="passwordType"
            placeholder="请输入密码"
            name="password"
            tabindex="2"
            autocomplete="on"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
            @keyup.enter.native="handleLogin"
          />
          <span class="show-pwd" @click="showPwd">
            <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
        <el-form-item style="width:100%;border-bottom:none;">
          <el-button
            :loading="loading"
            size="medium"
            type="primary"
            class="login-btn"
            @click.native.prevent="handleLogin"
          >
            <span v-if="!loading">登 录</span>
            <span v-else>登 录 中...</span>
          </el-button>
        </el-form-item>
        <div style="width:100%;text-align:center">
          <span style="font-size:14px;color:#999"
                @click="lostPassword">
             忘记密码</span>
        </div>
      </el-form>
      <!--  底部
      <div class="el-login-footer">
        <span>Copyright © 2018-2021 ruoyi.vip All Rights Reserved.</span>
      </div>
      -->
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'

export default {
  name: "Login",
  data() {
    return {
      codeUrl: "",
      cookiePassword: "",
      passwordType: 'password',
      capsTooltip:'',
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        code: "",
        uuid: ""
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "用户名不能为空" }
        ],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" }
        ],
        code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
      },
      loading: false,
      redirect: undefined
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        console.log(route)
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created() {
    this.getCookie();
  },
  methods: {

    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get('rememberMe')
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password: password === undefined ? this.loginForm.password : decrypt(password),
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
      };
    },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = '';
      } else {
        this.passwordType = 'password';
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          if (this.loginForm.rememberMe) {
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
            Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove('rememberMe');
          }
          this.$store.dispatch("Login", this.loginForm).then(() => {
            this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
          }).catch(() => {
            this.loading = false;
            this.getCode();
          });
        }
      });
    }

    , lostPassword(){
        this.$alert('忘记密码，请联系数据中台部门陈刚', '提示', {
           confirmButtonText: '确定',
        });
     }


  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
$bg: #fff;
$shadow: #283443;
$light_gray: #fff;
$cursor: #283443;
$dark_gray: #889aa4;
$title: #0F70ED;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-page .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/images/login_bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  .logo{
     /* width: 426px; */
     /* height: 150px; */
     position: relative;
     left: 350px;
     top: -201px;
     img{
       width:100%;
     }
   }
   .login-container {
     display: flex;
     justify-content: center;
     align-items: center;
      left: 100px;
      top: -110px;
      position: relative;
   }
   .el-input {
     display: inline-block;
     height: 39px;
     width: 84%;
     input {
       background: transparent;
       border:none;
       -webkit-appearance: none;
       border-radius: 0px;
       padding: 12px 5px 12px 15px;
       height: 20px;
       font-size:20px;
       caret-color: $cursor;
       &:-webkit-autofill {
         box-shadow: 0 0 0px 1000px $bg inset !important;
         -webkit-text-fill-color: $shadow !important;
       }
     }
   }

   .el-form-item {
     color: #454545;
     margin:35px 16px;
     border-bottom: 1px solid rgba(232, 234, 237, 1);
     .el-form-item__error {
       left: 30px;
     }
   }
   .el-form-item:nth-of-type{
     border-bottom: none!important;
   }
   .login-btn {
     font-size:26px;
     display: block;
     width: 302px;
     height: 60px;
     margin-left:0;
     border-radius: 10px;
   }
 }
 .login-form {
   position: relative;
   width: 428px;
   max-width: 100%;
   padding: 76px 58px 53px;
   margin: 0 auto;
   overflow: hidden;
   background: #fff;
   border-radius: 3px;
    opacity:0.9;
 }
 .svg-container {
   padding: 6px 5px 6px 10px;
   color: $dark_gray;
   width: 36px;
   display: inline-block;
   font-size:20px;
 }

 .title-container {
   position: relative;
   .title {
     /*font-family: Source Han Sans CN;**/
    font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
    font-size: 30px;
    color: $title;
    margin: 0px auto 10px auto;
    text-align: center;
    font-weight: bold;
    color: linear-gradient(0deg, #006CFF 0%, #019EF0 100%);
    line-height: 30px;
  }
}

.show-pwd {
  position: absolute;
  right: 10px;
  top: 7px;
  font-size: 16px;
  color: $dark_gray;
  cursor: pointer;
  user-select: none;
}




.logo-words{
   position: relative;
   top: -26px;
   right: 112px;
   color: whitesmoke;
   font-size: 30px;
   font-style: italic;
}
.line-spit{
   height: 476px;
   width: 1px;
   background-color: gainsboro;
   left: 0px;
   top: -110px;
   position: relative;
}



</style>
